package cn.kk.communication.dao.impl;
/*
 *@author KK on 2022.11.19 10:52
 */

import cn.kk.communication.dao.BaseDao;
import cn.kk.communication.entity.Communication;

import java.sql.SQLException;
import java.util.List;

public class CommunicationDao extends BaseDao<Communication> {
    /**
     * 通过名字查找用户信息
     * @param username
     * @return
     * @throws SQLException
     */
    public Communication getByName(String username) throws SQLException {
        String sql = "SELECT cid,NAME,PASSWORD,phone,address FROM communication WHERE NAME = ? ";
        return this.query(sql,username);
    }

    /**
     * 获取全部信息
     * @return
     */
    public List<Communication> getAll() throws SQLException {
        String sql = "SELECT cid,NAME,PASSWORD,phone,address FROM communication ";
        return this.queryAll(sql);
    }

    /**
     * 注册
     * @param addCommunication
     * @return
     */
    public  int addCommunication(Communication addCommunication) throws SQLException {
        String sql = "insert into communication values (default,?,?,?,?)";
        return this.update(sql,addCommunication.getName(),addCommunication.getPassword(),addCommunication.getPhone(),addCommunication.getAddress());
    }

}
